Skip to main content
POST
/
api
/
pedidos
/
{pedidoId}
/
detalles
Add Item to Order
curl --request POST \
  --url https://api.example.com/api/pedidos/{pedidoId}/detalles \
  --header 'Content-Type: application/json' \
  --data '
{
  "producto_id": 123,
  "cantidad": 123,
  "precioUnitario": 123
}
'
{
  "201": {},
  "400": {},
  "401": {},
  "403": {},
  "404": {},
  "detalle_id": 123,
  "producto_id": 123,
  "nombre": "<string>",
  "cantidad": 123,
  "precioUnitario": 123,
  "subtotal": 123
}

Authentication

This endpoint requires JWT authentication. Include the Bearer token in the Authorization header.

Path Parameters

pedidoId
long
required
The unique identifier of the order to which you want to add an item

Request Body

producto_id
long
required
ID of the product to add to the order
cantidad
integer
required
Quantity of the product to add (must be greater than 0)
precioUnitario
number
required
Price per unit for this line item. Typically the current product price at time of addition.

Response

Returns the newly created order detail object.
detalle_id
long
Unique identifier for the new line item
producto_id
long
ID of the product added
nombre
string
Product name
cantidad
integer
Quantity ordered
precioUnitario
number
Price per unit
subtotal
number
Line total (cantidad × precioUnitario)

Example Request

cURL
curl -X POST "http://localhost:8080/api/pedidos/123/detalles" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "producto_id": 5,
    "cantidad": 2,
    "precioUnitario": 299.00
  }'
JavaScript
const response = await fetch('http://localhost:8080/api/pedidos/123/detalles', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    producto_id: 5,
    cantidad: 2,
    precioUnitario: 299.00
  })
});
const newDetail = await response.json();
Python
import requests

headers = {
    'Authorization': f'Bearer {token}',
    'Content-Type': 'application/json'
}
data = {
    'producto_id': 5,
    'cantidad': 2,
    'precioUnitario': 299.00
}
response = requests.post(
    'http://localhost:8080/api/pedidos/123/detalles',
    headers=headers,
    json=data
)
detail = response.json()

Example Response

{
  "detalle_id": 45,
  "producto_id": 5,
  "nombre": "Sofá Klippan 2 plazas",
  "cantidad": 2,
  "precioUnitario": 299.00,
  "subtotal": 598.00
}

Status Codes

201
Created
Order detail added successfully
400
Bad Request
Invalid request body (e.g., negative quantity, missing fields)
401
Unauthorized
Missing or invalid JWT token
403
Forbidden
User does not have permission to modify this order
404
Not Found
Order or product with specified ID not found

Use Cases

  • Order modification: Add items to an existing order before it’s finalized
  • Upselling: Allow customers to add additional items during checkout
  • Admin adjustments: Enable administrators to manually add items to orders
  • Bulk ordering: Add multiple items to an order programmatically
The price is locked at the time the item is added. Subsequent product price changes won’t affect this order detail.
Ensure the order status allows modifications. Some order states (e.g., ENVIADO, ENTREGADO) may not permit adding items.